package com.tybbank.web;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

import com.tybbank.Activity.AndroidBug5497Workaround;
import com.tybbank.Base.BaseActivity;
import com.tybbank.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/3/23 0023.
 */
//公共用web
public class WebActivity extends BaseActivity {

    @BindView(R.id.webview)
    WebView webview;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.ddd)
    TextView ddd;
    private String title;
    private String url;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);
        ButterKnife.bind(this);
        AndroidBug5497Workaround.assistActivity(this);  //  web页 输入框自动上弹
        try {
            title = getIntent().getStringExtra("title");
            url = getIntent().getStringExtra("url");
        } catch (Exception e) {

        }
        toolbar(toolbar, title, R.mipmap.icon_close);
        if (isNavigationBarAvailable()==false){
            ddd.setVisibility(View.VISIBLE);
        }else {
            ddd.setVisibility(View.GONE);
        }
        loginwebview(url);    //webview的设置

    }
    /**
     * 获取是否存在NavigationBar
     *
     * @return
     */
    //是否有下方虚拟栏
    private static boolean isNavigationBarAvailable() {
        boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
        return (!(hasBackKey && hasHomeKey));
    }

    @Override
    public void LeftClose() {
        super.LeftClose();
        WebActivity.this.finish();
    }

    private void loginwebview(String str) {
        webview.loadUrl(str);
        WebSettings settings = webview.getSettings();
        settings.setJavaScriptEnabled(true);
    }

}
